#include "OclLapack.h"
#include "../clUtils.h"
#include "clAmdBlas.h"
#include "../AmdConvertEnum.h"
#include "../ClMem.h"
#include <algorithm>

using namespace std;

void OclLapack::strmm(const char* side,
		const char* uplo, 
		const char* transA,
		const char* diag,
		int m, int n, float alpha,
		const cl_ptr a, int lda,
		cl_ptr b, int ldb)
{
	Measure measure("strmm-ocl");
	
	cl_event event;	
	CL_CHECK(clAmdBlasStrmmEx(clAmdBlasColumnMajor,
			toAmdSide(side), toAmdUplo(uplo), 
			toAmdTrans(transA), toAmdDiag(diag),
			m, n, alpha,
			a.handle, a.offset, lda,
			b.handle, b.offset, ldb,
			1, &queue, 0, NULL, &event));
	
	ClEvent(event).wait();
}

int OclLapack::strmm(char *side, char *uplo, char *transa, char *diag, 
		int *m, int *n, float *alpha, float *a, int *lda, float *b, 
		int *ldb) 
{
	size_t ka = (tolower(side[0]) == 'l') ? *m : *n;
	ClMem<float> memA(queue, (*lda) * ka, a);	
		
	size_t sizeB = (*ldb) * (*n);
	ClMem<float> memB(queue, sizeB, b);
        
	strmm(side, uplo, transa, diag, *m, *n, *alpha,
		cl_ptr(memA), *lda,
        cl_ptr(memB), *ldb);

	memB.beginRead(b, 0, sizeB).wait();
    return 0;
}
